package com.alexsh.dao.impl;

import com.alexsh.dao.BookDAO;
import com.alexsh.domain.Book;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @author <a href="mailto:ashmygin@luxoft.com">Alexander Shmygin</a>
 * @version 1.0
 */
public class BookDAOImpl implements BookDAO {

    private JdbcTemplate jdbcTemplate;

    public void setDataSource(final DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public void save(final Book book) {
        jdbcTemplate.update("insert into test (book_id, title, authors, publication_date) values(?, ?, ?, ?)",
            new Object[]{book.getId(),
                         book.getTitle(),
                         book.getAuthors(),
                         book.getPubDate()});
    }
}
